home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / sort / Source / acur.c next >
C/C++ Source or Header  |  1993-06-17  |  2KB  |  94 lines

  1. #include <Quickdraw.h>
  2. #include <Resources.h>
  3. #include <Memory.h>
  4. #include <Events.h>
  5.  
  6. #include "acur.h"
  7.  
  8. #define SPIN_DELAY 15L
  9.  
  10. typedef struct {
  11.     short count;
  12.     short counter;
  13.     short id;
  14.     short padd;
  15. } acur, *acurptr, ** acurhand;
  16.  
  17. static acurptr aptr = nil;
  18. static long lastspin = 0;
  19.  
  20. void Initacur(short id)
  21. {
  22.     Handle rhand;
  23.     short count;
  24.     short *id_base;
  25.     CursHandle cur;
  26.  
  27.     rhand = GetResource('acur', id);
  28.     if ((ResError() == noErr) && (rhand != nil)) {
  29.         LoadResource(rhand);
  30.         HLock(rhand);
  31.         HNoPurge(rhand);
  32.         if (MemError() != noErr) {
  33.             return;
  34.         }
  35.         aptr = (acurptr)*rhand;
  36.         aptr->counter = 0;
  37.         id_base = & (aptr->id);
  38.  
  39.         for (count = aptr->count; count > 0; count--) {
  40.             cur = (CursHandle) GetResource('CURS', id_base[(aptr->count - count)<<1]);
  41.             if (cur == nil) {
  42.                 return;
  43.             }
  44.             HLock((Handle)cur);
  45.             HNoPurge((Handle)cur);
  46.         }
  47.     }
  48.     lastspin = TickCount();
  49. }
  50.  
  51. void SpinCursor()
  52. {
  53.     CursHandle cur;
  54.     short* id_base;
  55.  
  56.     extern void HandleEvent(void);
  57.  
  58.     if ((TickCount() - lastspin) >= SPIN_DELAY) {
  59.         HandleEvent();
  60.         lastspin = TickCount();
  61.         if (aptr != nil) {
  62.             aptr->counter++;
  63.             if (aptr->counter >= aptr->count) {
  64.                 aptr->counter = 0;
  65.             }
  66.             id_base =  & (aptr->id);
  67.             cur = (CursHandle) GetResource('CURS', id_base[(aptr->counter)<<1]);
  68.             if (cur != nil) {
  69.                 SetCursor(*cur);
  70.             }
  71.         }
  72.     }
  73. }
  74.  
  75. void DisposAcur()
  76. {
  77.     CursHandle cur;
  78.     Handle rhand;
  79.     short count, *id_base;
  80.  
  81.     rhand = RecoverHandle((Ptr)aptr);
  82.     
  83.     if (rhand != nil) {
  84.         id_base =  & (aptr->id);
  85.         for (count = aptr->count; count > 0; count--) {
  86.             cur = (CursHandle) GetResource('CURS', id_base[(aptr->count - count)<<1]);
  87.             if (cur != nil) {
  88.                 ReleaseResource((Handle)cur);
  89.             }
  90.         }
  91.         ReleaseResource(rhand);
  92.     }
  93. }
  94.